#include <iostream>
#include <thread>
#include <future>
#include <chrono>

//通过在线程中对promise对象设置数据，其他线程中通过future获取所设
void Add(int num1,int num2,std::promise<int>& prom)
{
    prom.set_value(num1+num2);
} 

int main()
{
    std::cout<<"-----------1-----------\n";
    
    std::promise<int> prom;

    std::future<int> fu = prom.get_future();

    std::thread thr(Add,11,22,std::ref(prom));

    int ret = fu.get();
    std::cout<<"sum = "<<ret<<std::endl;

    return 0;
}